/**
 * debug_function.c
 * develop a debug function use variable arguments list.
 * @author: zt 2013-10-14
 */
#include<stdio.h>
#include<stdarg.h>

#define DEBUG

#ifdef DEBUG
#define Q(arg_list) debug_write arg_list /* Usage: Q(("format", arglist...)); */
#else
#define Q(arg_list)
#endif

void debug_write(char* format, ...)
{
	va_list vaList;
	
	setbuf(stderr, NULL);
	va_start(vaList, format);
	vfprintf(stderr, format, vaList);
	va_end(vaList);
	
	return ;
}

#define Q_INT(num) fprintf(stderr, #num"=%d\n", num)
#define Q_STR(str) fprintf(stderr, #str"=%s\n", str)
#define Q_DOUBLE(num) fprintf(stderr, #num"=%f\n", num)

int main(void)
{
	int i = 10;
	char* name = "test";
	double d = 12.2;
	
	Q(("debug_write: %s", "hello debug!"));
	Q_INT(i);
	Q_STR(name);
	Q_DOUBLE(d);
	
	getchar();
	return 0;	
}
